package simple

import "strings"

func longestCommonPrefix(strs []string) string {

	if len(strs) == 0 {
		return ""
	}
	if len(strs) == 1 {
		return strs[0]
	}

	var sb strings.Builder
	for i := 0; i < len(strs[0]); i++ {
		c := strs[0][i]
		flag := true
		for j := 1; j < len(strs); j++ {
			if i >= len(strs[j]) {
				flag = false
				break
			}
			if c != strs[j][i] {
				flag = false
				break
			}
		}
		if !flag {
			break
		}
		sb.WriteByte(c)
	}

	return sb.String()
}
